var downloadHtml = require("cloud/model/downloadHtml.js");
var schedule = require("node-schedule");

function getZhangFuFromWeb() {
}
module.exports = getZhangFuFromWeb;

getZhangFuFromWeb.get = function (callback) {
　　var rule = new schedule.RecurrenceRule();
　　var times = [];
　　for(var i=1; i<60; i++){
      if (i % 1 === 0) {
　　　　times.push(i);
      }
　　}
　　rule.second = times;
　　var j = schedule.scheduleJob(rule, function(){
      getData();
　　});
}

function getData() {
  var url = "http://hqdigi2.eastmoney.com/EM_Quote2010NumericApplication/cache.aspx?Type=c1&Reference=xml";
  downloadHtml.download(url, function(data) {
    if (data) {
       eval(data);
//       console.log(C1Cache.record);
//       var shanghai = C1Cache.record[0].split(",");
//       var shenzheng = C1Cache.record[1].split(",");

       var ZhangFu = AV.Object.extend("ZhangFu");
       var query = new AV.Query(ZhangFu);
       query.get("54f81243e4b0c976f03d8583", {
         success: function(zhangFu) {
           // The object was retrieved successfully.
             if (typeof(C1Cache) !== "undefined") {// 判断指定的变量是否存在
                zhangFu.set("data",C1Cache);
                zhangFu.save(null, {
                  success: function(test) {
                    // Execute any logic that should take place after the object is saved.
//                    console.log('New object created with objectId: ' + test.id);
                  },
                  error: function(test, error) {
                    // Execute any logic that should take place if the save fails.
                    // error is a AV.Error with an error code and description.
 //                   console.log('Failed to create new object, with error code: ' + error.description);
                  }
                });
             }
         },
         error: function(object, error) {
           // The object was not retrieved successfully.
           // error is a AV.Error with an error code and description.
         }
       });
    } else {
        console.log("ha");
    } 
  });
}

function test() {
  // 创建AV.Object子类.
  // 该语句应该只声明一次
  var GameScore = AV.Object.extend("GameScore");
  
  // 创建该类的一个实例
  var gameScore = new GameScore();
  gameScore.set("score", 1337);
  gameScore.set("playerName", "Sean Plott");
  gameScore.set("cheatMode", false);
  gameScore.save(null, {
    success: function(gameScore) {
      // Execute any logic that should take place after the object is saved.
      console.log('New object created with objectId: ' + gameScore.id);
    },
    error: function(gameScore, error) {
      // Execute any logic that should take place if the save fails.
      // error is a AV.Error with an error code and description.
      console.log('Failed to create new object, with error code: ' + error.description);
    }
  });
}
